import { defHttp } from '@/utils/http/axios';
import { NewsParams, NewsListGetResultModel, NewsModel } from './model/newsModel';

enum Api {
  NEWS_LIST = '/news/page',
  NEWS_SAVE = '/news/save',
  NEWS_DELETE = '/news/del',
  NEWS_DETAIL = '/news/detail',
}

/**
 * @description: Get sample list value
 */

export const newsListApi = (params: NewsParams) =>
  defHttp.post<NewsListGetResultModel>({
    url: Api.NEWS_LIST,
    params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

export const newsSaveApi = (params: NewsParams) =>
  defHttp.post<number>({
    url: Api.NEWS_SAVE,
    params,
    headers: {
      // @ts-ignore
    },
  });

export const newsDeleteApi = (params: NewsParams) =>
  defHttp.postForm<number>({
    url: Api.NEWS_DELETE,
    params,
    headers: {
      // @ts-ignore
    },
  });

export const newsDetailApi = (id: number) =>
  defHttp.get<NewsModel>({
    url: Api.NEWS_DETAIL,
    params: { id: id },
    headers: {},
  });
